package org.gp.core.web;

import com.alibaba.fastjson.JSON;
import org.gp.core.annotation.AuthOperate;
import org.gp.core.entity.User;
import org.gp.core.entity.dto.ResponseDTO;
import org.gp.core.service.IBlacklistService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 黑名单表  前端控制器
 * </p>
 *
 * @author LuoLiang
 * @since 2017-03-14
 */
@RestController
@RequestMapping("/blacklist")
public class BlacklistController {
    @Resource
    private IBlacklistService blacklistService;

    @RequestMapping(value = "adduser", method = RequestMethod.POST)
    public String addUser(Integer userId, String reason) {
        ResponseDTO dto = blacklistService.addUser(userId, reason);

        return JSON.toJSONString(dto);
    }

    @RequestMapping(value = "removeuser", method = RequestMethod.POST)
    public String removeUser(Integer userId) {
        ResponseDTO dto = blacklistService.removeUser(userId);

        return JSON.toJSONString(dto);
    }

    @RequestMapping(value = "userblacklist", method = RequestMethod.GET)
    @AuthOperate
    public String UserBlackList(Integer currentPage, Integer pageSize) {
        ResponseDTO<List<User>> dto = blacklistService.getBlackList(currentPage, pageSize);

        return JSON.toJSONString(dto);
    }
}
